package org.tagging.service.impl.indonesian;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.tagging.dao.indonesian.AbbreviationIndonesianMapper;
import org.tagging.model.Abbreviation;
import org.tagging.model.AbbreviationIndonesian;
import org.tagging.service.AbbreviationService;
import org.tagging.service.impl.other.ClientUserServiceImpl;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class AbbreviationIndonesianServiceImpl implements AbbreviationService<AbbreviationIndonesian> {
    @Resource
    private AbbreviationIndonesianMapper abbreviationIndonesianMapper;
    @Autowired
    private ClientUserServiceImpl userDetailsService;

    @Override
    public List<AbbreviationIndonesian> queryByTagId(Integer tagId) {
        return abbreviationIndonesianMapper.queryByTagId(tagId);
    }

    @Override
    public void update(Abbreviation abbreviation) {
        Integer userId = userDetailsService.retrieveCurrentUserId();
        abbreviation.setUpdateBy(userId);
        abbreviation.setUpdateTime(LocalDateTime.now());
        abbreviationIndonesianMapper.updateSelective(abbreviation);
    }

    @Override
    public void add(Abbreviation abbreviation) {
        Integer userId = userDetailsService.retrieveCurrentUserId();
        abbreviation.setUpdateTime(LocalDateTime.now());
        abbreviation.setStatus(1);
        abbreviation.setUpdateBy(userId);
        abbreviationIndonesianMapper.insertSelective(abbreviation);
    }

    @Override
    public AbbreviationIndonesian queryById(Integer id) {
        return abbreviationIndonesianMapper.queryById(id);
    }

    @Override
    public List<AbbreviationIndonesian> queryByTimePeriod(LocalDateTime startTime, LocalDateTime endTime, int mode) {
        return abbreviationIndonesianMapper.queryByTimePeriod(startTime, endTime, mode);
    }
}
